package com.huitone.smspfm.interfacz.model;

import java.util.List;

import com.huitone.smspfm.interfacz.logger.ExtLogger;

import com.bin.common.utils.StringUtils;

/**   
* @Title SmsDeliver.java 
* @Package com.huitone.smspfm.interfacz.model 
* @Description TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年7月6日 下午5:36:28 
* @version V1.0   
*/
public class SmsDeliver {
	
	private static final ExtLogger logger = ExtLogger.create(SmsDeliver.class);

	protected String srvNode = null;
	protected String phoneNumber = null;
	protected String sendPort = null;
	protected String smcontent = null;
	protected String recvTime = null;
	protected String serialSegment = null;
	protected Long serialPart1 = null;
	protected Long serialPart2 = null;
	protected Long serialPart3 = null;
	protected String serialno = null;
	protected String moDealListEl = null;
	protected String orgSrvNode = null;
	
	public static SmsDeliver parse(List<String> list) {
		
		SmsDeliver deliver = new SmsDeliver();
		
		try {
			
			deliver.setMoDealListEl(StringUtils.toString(list.get(7)));
			
			deliver.setSrvNode(StringUtils.toString(list.get(0)));
			deliver.setPhoneNumber(StringUtils.toString(list.get(1)));
			deliver.setSendPort(StringUtils.toString(list.get(2)));
			deliver.setSmcontent(StringUtils.toString(list.get(3)));
			deliver.setRecvTime(StringUtils.toString(list.get(4)));
			deliver.setSerialSegment(StringUtils.toString(list.get(5)));
			deliver.setOrgSrvNode(StringUtils.toString(list.get(6)));
			
		} catch (Exception e) {
			logger.error("上行短信解析异常", e);
		}
		
		return deliver;
	}
	
	public boolean isWellInformed() {
		return !StringUtils.isEmpty(srvNode) 
				&& !StringUtils.isEmpty(phoneNumber)
				&& !StringUtils.isEmpty(sendPort)
				&& !StringUtils.isEmpty(serialSegment);
	}
	
	public String getSrvNode() {
		return srvNode;
	}
	public void setSrvNode(String srvNode) {
		this.srvNode = srvNode;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	public String getSendPort() {
		return sendPort;
	}
	public void setSendPort(String sendPort) {
		this.sendPort = sendPort;
	}
	public String getSmcontent() {
		return smcontent;
	}
	public void setSmcontent(String smcontent) {
		this.smcontent = smcontent;
	}
	public String getRecvTime() {
		return recvTime;
	}
	public void setRecvTime(String recvTime) {
		this.recvTime = recvTime;
	}
	public String getSerialSegment() {
		return serialSegment;
	}
	public void setSerialSegment(String serialSegment) {
		this.serialSegment = serialSegment;
		
		String[] strings = StringUtils.split(serialSegment, ",");
		
		if (strings != null) {
			try {
				setSerialPart1(StringUtils.toLong(strings[0]));
				setSerialPart2(StringUtils.toLong(strings[1]));
				setSerialPart3(StringUtils.toLong(strings[2]));
			} catch (Exception e) {
				logger.error("解析上行短信Hash表中的序列SerialSegment时出错:" + e.getClass().getName() + ":" + e.getMessage() + 
						", 其中SerialSegment字段信息为:" + serialSegment + ", 从上行短信队列读取的[序列:号码]为:" + moDealListEl);
			}
		}
		
		setSerialno(StringUtils.replace(serialSegment, ",", ""));
	}
	public Long getSerialPart1() {
		return serialPart1;
	}
	public void setSerialPart1(Long serialPart1) {
		this.serialPart1 = serialPart1;
	}
	public Long getSerialPart2() {
		return serialPart2;
	}
	public void setSerialPart2(Long serialPart2) {
		this.serialPart2 = serialPart2;
	}
	public Long getSerialPart3() {
		return serialPart3;
	}
	public void setSerialPart3(Long serialPart3) {
		this.serialPart3 = serialPart3;
	}

	public String getSerialno() {
		return serialno;
	}

	public void setSerialno(String serialno) {
		this.serialno = serialno;
	}

	@Override
	public String toString() {
		return "SmsDeliver [srvNode=" + srvNode + ", phoneNumber=" + phoneNumber + ", sendPort=" + sendPort
		        + ", smcontent=" + smcontent + ", recvTime=" + recvTime + ", serialSegment=" + serialSegment
		        + ", serialPart1=" + serialPart1 + ", serialPart2=" + serialPart2 + ", serialPart3=" + serialPart3
		        + ", serialno=" + serialno + ", moDealListEl=" + moDealListEl + ", orgSrvNode=" + orgSrvNode + "]";
	}

	public String getMoDealListEl() {
		return moDealListEl;
	}

	public void setMoDealListEl(String moDealListEl) {
		this.moDealListEl = moDealListEl;
	}

	public String getOrgSrvNode() {
		return orgSrvNode;
	}

	public void setOrgSrvNode(String orgSrvNode) {
		this.orgSrvNode = orgSrvNode;
	}
	
}
